package com.health.trans.pojo;


import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @author nqlz
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class CtTimeDto implements Cloneable {
    private Date maxDate;
    private Date minDate;
    private Date targetDate;
    private long count;

    public Date addTargetDate(Date date, int day) {
        return DateUtil.offsetDay(date, day);
    }

    public CtTimeDto setMinDate(Date minDate) {
        if (this.minDate == null) {
            this.minDate = DateUtil.offsetSecond(minDate, -1);
            if (this.targetDate == null) {
                this.targetDate = minDate;
            }
            return this;
        }
        this.minDate = minDate;
        return this;
    }

    public boolean hasDate() {
        return DateUtil.compare(targetDate, maxDate) < 0;
    }


    public boolean intervalZero() {
        return DateUtil.between(DateUtil.offsetDay(targetDate, -1), minDate, DateUnit.DAY) == 0;
    }

    public boolean gtMax() {
        return DateUtil.compare(targetDate, maxDate) >= 0 && DateUtil.between(targetDate, maxDate, DateUnit.DAY) > 0;
    }


}
